package top.kpromise.user.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.kpromise.user.model.response.UserTokenModel;

@Repository
public interface UserTokenMapper {

    @Select("select * from user_token where userId = #{userId} and clientId = #{clientId}")
    UserTokenModel getToken(String userId, String clientId);

    @Update("update user_token set updateAt = #{updateAt}, refreshToken = #{refreshToken}, accessToken = #{accessToken} " +
            "where userId = #{userId} and clientId = #{clientId} limit 1")
    void updateToken(UserTokenModel userTokenModel);

    @Insert("insert into user_token (userId, clientId, refreshToken, accessToken, createAt, updateAt) values (#{userId}, " +
            "#{clientId}, #{refreshToken}, #{accessToken}, #{createAt}, #{updateAt})")
    void insertToken(UserTokenModel userTokenModel);
}
